//Home页的数据仓库

//引入请求三级联动数据的方法
import { reqCategoryData, reqGetBannerList, reqGetFloorList } from '@/api'
const actions = {
  //请求三级联动的数据
  async getCategoryList(context) {
    //reqCategoryData 需要返回一个promise对象
    //需要用await 接收成功的返回结果  需要与async结合使用
    const CategoryList = await reqCategoryData();
    context.commit('GETCATEGROYLIST', CategoryList)
  },
  //去mock中请求banner的数据
  async getBannerList({ commit }) {
    const bannerList = await reqGetBannerList()
    commit('GETBANNERLIST', bannerList)
  },
  //由home页面来请求floor组件的数据
  async getFloorList({ commit }) {
    let result = await reqGetFloorList()
      //是否成功请求到数据 成功请求之后再把数据传给mutations处理数据
    if (result.code == 200) {
      commit('GETFLOORLIST', result.data)
    }
  }
}
const mutations = {
  //接收到三级列表的数据，并把数据赋值到state中
  GETCATEGROYLIST(state, CategoryList) {
    state.CategoryList = CategoryList
  },
  //接受到bannerlist的数据，并把数据赋值到state中
  GETBANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  //接收到floorlist 的数据，并把数据赋值到state中
  GETFLOORLIST(state, floorList) {
    state.floorList = floorList
  }
}
const state = {
  CategoryList: [],
  bannerList: [],
  floorList: []
}
const getters = {}

export default { actions, mutations, state, getters }